package com.wtwd.device.utils;

import com.alibaba.fastjson.JSONObject;
import com.wtwd.device.common.RespCode;
import com.wtwd.device.model.vo.ResultVO;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpResponse;
import reactor.core.publisher.Mono;

/**
 * @author zdl
 * @Description
 * @create 2021-08-19 10:12
 */
public class FilterUtil {
    public static Mono<Void> response(ServerHttpResponse response, RespCode respCode) {
        byte[] bytes = JSONObject.toJSONBytes(ResultVO.error(respCode));
        HttpHeaders headers = response.getHeaders();
        headers.add("Content-Type", MediaType.APPLICATION_JSON_VALUE);
        DataBuffer wrap = response.bufferFactory().wrap(bytes);
        return response.writeWith(Mono.just(wrap));
    }

}
